#include "qframeeditorsimple.h"
#include "ui_qframeeditorsimple.h"
#include <QAction>
QFrameEditorSimple::QFrameEditorSimple(QWidget *parent,QString hide) :
    QWidget(parent),
    ui(new Ui::QFrameEditorSimple)
{
    ui->setupUi(this);
    toolBar = new QToolBar("tools",this);
    toolBar->setMinimumWidth(toolBar->sizeHint().width());
    ui->verticalSpacer->changeSize(
                 20,                // 宽度（水平方向最小尺寸）
                 30,               // 高度（垂直方向最小尺寸）
                 QSizePolicy::Minimum,  // 水平方向策略
                 QSizePolicy::Fixed     // 垂直方向策略（固定高度
    );
    // --------------------------------------------
    // 创建动作（图标、文本、父对象）
    QAction *newAction  = new QAction(QIcon(":/icons/icon_base/filenew.png"), "New", this);
    QAction *openAction = new QAction(QIcon(":/icons/icon_base/file.png"), "Open", this);
    QAction *saveAction = new QAction(QIcon(":/icons/icon_base/save.png"), "Save", this);

    if(hide.contains("A1") || hide.contains("A*")) //按照组内容进行对应按钮的屏蔽
    {
        newAction->setVisible(false);
    }
    if(hide.contains("A2")|| hide.contains("A*"))
    {
        openAction->setVisible(false);
    }
    if(hide.contains("A3")|| hide.contains("A*"))
    {
        saveAction->setVisible(false);
    }
    // 添加动作到工具栏
    toolBar->addAction(newAction);
    toolBar->addAction(openAction);
    toolBar->addAction(saveAction);

    // 增加目录处理
    QAction *dirAction = new QAction(QIcon(":/icons/icon_base/dir.png"), "Dir", this);
    QAction *dirSaveAction = new QAction(QIcon(":/icons/icon_base/layers.png"), "DirSave", this);

    toolBar->addAction(dirAction);
    toolBar->addAction(dirSaveAction);
    if(hide.contains("B1") || hide.contains("B*"))
    {
        dirAction->setVisible(false);
    }
    if(hide.contains("B2") || hide.contains("B*"))
    {
        dirSaveAction->setVisible(false);
    }

    // 计算所有按钮的总宽度（假设每个按钮宽80px）
    int totalWidth = toolBar->actions().size() * 80;
    // 设置工具栏的最小宽度
    toolBar->setMinimumWidth(totalWidth);

    // --------------------------------------------
    // 增加信号处理逻辑
    connect(newAction , &QAction::triggered, this, &QFrameEditorSimple::file_new_trig ); //转发信号到嵌入的模块
    connect(openAction, &QAction::triggered, this, &QFrameEditorSimple::file_open_trig); //转发信号到嵌入的模块
    connect(saveAction, &QAction::triggered, this, &QFrameEditorSimple::file_save_trig); //转发信号到嵌入的模块
    //dir
    connect(dirAction, &QAction::triggered, this, &QFrameEditorSimple::dir_open_trig); //转发信号到嵌入的模块
    connect(dirSaveAction, &QAction::triggered, this, &QFrameEditorSimple::dir_save_trig); //转发信号到嵌入的模块

}

QFrameEditorSimple::~QFrameEditorSimple()
{
    delete ui;
}

void QFrameEditorSimple::addWidget(QWidget *page, QString name)
{
    ui->ui_pages->addTab(page,name);
}


